package cn.edu.nwsuaf.examcenter.service.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import cn.edu.nwsuaf.examcenter.model.PageModel;
import cn.edu.nwsuaf.examcenter.pojo.ExamItemType;
import cn.edu.nwsuaf.examcenter.service.ExamItemTypeService;
import cn.edu.nwsuaf.examcenter.utils.UniqueKeyUtils;

@Service(value="examItemTypeService")
public class ExamItemTypeServiceImpl extends BaseServiceImpl<ExamItemType> implements ExamItemTypeService {

	@Override
	public String addExamItemType(ExamItemType examItemType) {
		// TODO Auto-generated method stub
		super.saveData(examItemType);
		return "success";
	}

	@Override
	public void loadExamItemType(ModelMap modelMap) {
		// TODO Auto-generated method stub
		PageModel<ExamItemType> pageModel = new PageModel<>();
		List<ExamItemType> list = super.findAll(ExamItemType.class);
		pageModel.setTotalrows(list.size());
		pageModel.setList(list);
		
		modelMap.addAttribute("pageModel",pageModel);
	}

	@Override
	public String importExamItemType(ExamItemType examItemType) {
		// TODO Auto-generated method stub
		super.saveData(examItemType);
		return "success";
	}

	@Override
	public String deleteExamItemType(String typeNo) {
		// TODO Auto-generated method stub
		super.deleteData(super.getById(ExamItemType.class, typeNo));
		return "success";
	}

	@Override
	public String deleteExamItemTypeList(String array) {
		// TODO Auto-generated method stub
		String[] typeNos = array.split(",");
		List<ExamItemType> list = new ArrayList<>();
		for(String s:typeNos){
			list.add(super.getById(ExamItemType.class, s));
		}
		super.deleteDataList(list);
		return "success";
	}
	
}
